package com.example.mutil;


import com.example.waitnotify.User;

/**
 * @author:CrazyShaQiuShi
 * @email:3105334046@qq.com
 * @descript:
 * @version:1.0.0
 */
public class SimpleMutilObject extends Thread {

    private User user;
    private String name;

    public SimpleMutilObject(User user, String name) {
        this.user = user;
        this.name = name;
    }

    @Override
    public void run() {
        while (true) {
            if (Thread.currentThread().isInterrupted()) {
                break;
            }
            synchronized (user) {
                try {
                    Thread.sleep(1000);
                    System.out.println(user.getName() + Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    Thread.interrupted();
                }
            }
            Thread.yield();
        }
    }
}
